package com.xls.box2023.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lzz.bottomencapsulation.holder.MvpRVViewHolder;
import com.xls.box2023.R;
import com.xls.box2023.entity.AppTeamUsersEntity;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class TuiGuangItemView extends MvpRVViewHolder<AppTeamUsersEntity> {
    private RecyclerView tg_list;
    private TextView tg_name;
    private TextView tg_jinrishouyi;
    private TextView tg_zongshouyi;
    private RelativeLayout tg_one;
    private ImageView tg_open;
    boolean isShowScore=true;
    public TuiGuangItemView(Context context, ViewGroup p) {
        super(R.layout.item_tuiguang, context, p);
    }

    public TuiGuangItemView(Context context, ViewGroup p, boolean isShowScore) {
        super(R.layout.item_tuiguang, context, p);
        this.isShowScore=isShowScore;
    }
    @Override
    public void initView() {
        tg_list = itemView.findViewById(R.id.tg_list);
        tg_name = itemView.findViewById(R.id.tg_name);
        tg_jinrishouyi = itemView.findViewById(R.id.tg_jinrishouyi);
        tg_zongshouyi = itemView.findViewById(R.id.tg_zongshouyi);
        tg_one = itemView.findViewById(R.id.tg_one);
        tg_open = itemView.findViewById(R.id.tg_open);
        tg_open.setVisibility(View.GONE);
        tg_open.setOnClickListener(this);
        tg_open.setSelected(false);
        tg_list.setVisibility(View.GONE);
        viewData.setIsopen(false);
        if (viewData.getList()!=null&&viewData.getList().size()>0){
            tg_list.setLayoutManager(new LinearLayoutManager(context));
            tg_list.setAdapter(new TuiGuang2Adapter(context,viewData.getList(),isShowScore));
            tg_open.setVisibility(View.VISIBLE);
        }
        tg_name.setText(viewData.getUsername());
//        tg_jinrishouyi.setText("今日收益："+viewData.getScore()+" 积分");
        tg_zongshouyi.setText("收益："+viewData.getScoreTotalStr()+" 元宝");

        if (isShowScore){
            tg_zongshouyi.setVisibility(View.VISIBLE);
        }else {
            tg_zongshouyi.setVisibility(View.INVISIBLE);
        }
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.tg_open) {
            if (viewData.getList()!=null&&viewData.getList().size()>0){
                viewData.setIsopen(!viewData.isIsopen());
                if (viewData.isIsopen()){
                    tg_open.setSelected(true);
                    tg_list.setVisibility(View.VISIBLE);
                }else {
                    tg_open.setSelected(false);
                    tg_list.setVisibility(View.GONE);
                }
            }
        }
    }
}
